package algorithm.leetcode.simple;

/*
 反转一个单链表
 */

/**
 * @author jack.wu
 * @version 1.0
 * @date 2020/10/20
 */
public class Question206 {

    public static void main(String[] args) {

    }

    public ListNode reverseList(ListNode head) {
        if (head == null || head.next == null) {
            return head;
        }
        ListNode temp = new ListNode(0);
        ListNode cur = head;
        ListNode next;
        while (cur != null) {
            next = cur.next;
            cur.next = temp.next;
            temp.next = cur;
            cur = next;
        }
        return temp.next;
    }

    private static class ListNode {
        int val;
        ListNode next;

        ListNode(int x) {
            val = x;
        }
    }
}
